#ifndef CM_SERVER_TIME_EVENT_MANAGER_INCLUDE
#define CM_SERVER_TIME_EVENT_MANAGER_INCLUDE

#include <hgl/type/ .h>
#include <hgl/thread/ThreadMutex.h>

using namespace hgl;

class TimeEvent
{
public:
	TimeEvent(double time);
	virtual ~TimeEvent() {}
	
public:
	double  TrigetTime() const {return triger_time;}
	
public:
	virtual bool OnEvent(double cur_time) = 0;
	
public:
	bool operator==(const TimeEvent& event) const
	{
		return triger_time == event.triger_time;
	}
	
	bool operator>(const TimeEvent& event) const
	{
		return triger_time > event.triger_time;
	}
	
	bool operator<(const TimeEvent& event) const
	{
		return triger_time < event.triger_time;
	}
	
	bool operator>=(const TimeEvent& event) const
	{
		return triger_time >= event.triger_time;
	}
	
	bool operator<=(const TimeEvent& event) const
	{
		return triger_time <= event.triger_time;
	}
protected:
	double triger_time;
	
};//class TimeEvent

class TimeObject :public TimeEvent
{
protected:
	TimeObject(double time,double interval):TimeEvent(time),interval_time(interval){}
	~TimeObject() {}
	
public:
	virtual bool OnEvent(double cur_time) = 0;
	
public:
	bool Update(double cur_time);

protected:
	virtual double CreateStandardTime(double cur_time) = 0;
	
protected:
	double interval_time;
};// class TimeObject 

class TimeEventAdapter
{
public:
	TimeEventAdapter(TimeEvent* event):event(event){}
	~TimeEventAdapter(){}
	
public:
	TimeEvent*  TimeEvent() const{return event;}

public:
	bool operator==(const TimeEventAdapter& adatper) const
	{
		return *event == *adatper.event;
	}
	
	bool operator>(const TimeEventAdapter& adatper) const
	{
		return *event > *adatper.event;
	}
	
	bool operator<(const TimeEventAdapter& adatper) const
	{
		return *event < *adatper.event;
	}
	
	bool operator>=(const TimeEventAdapter& adatper) const
	{
		return *event >= *adatper.event;
	}
	
	bool operator<=(const TimeEventAdapter& adatper) const
	{
		return *event <= *adatper.event;
	}
	
private:
	TimeEvent *event;
};// class TimeEventAdapter

class TimeEventManager
{
public:
	TimeEventManager(){is_update = false;}
	~TimeEventManager(){}
	
public:
	bool Update(double cur_time);
	
	bool AddEvent(const TimeEventAdapter& event);
	bool DeleteEvent(const TimeEventAdapter& event);
	
private:
	 <TimeEventAdapter> event_list;
	
	bool is_update;
	ThreadMutex mutex;
};//class TimeEventManager

extern TimeEventManager time_event_mananger;

#endif //CM_SERVER_TIME_EVENT_MANAGER_INCLUDE